package com.eimf.saf.security.util.secret;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author eden
 * @date 2013-11-25 下午3:43:14
 * @Description: 密码工具类
 */
public class PasswordUtil
{
    private static Log logger = LogFactory.getLog(PasswordUtil.class);

    public static boolean verifyPassword(final String userid, final String p_password, final String c_password)
    {
        return PasswordUtil.cryptPassword(userid, p_password).equals(c_password);
    }

    public static String cryptPassword(final String staffId, final String password)
    {
        byte[] b = null;
        try
        {
            b = CryptUtil.encrypt(password, staffId, CryptUtil.ALGORITHM_PBEWithMD5AndDES);
        } catch (final Exception e)
        {
            PasswordUtil.logger.error("加密用户密码错误：" + e.getMessage(), e);
            return null;
        }
        return CryptUtil.md5(b);
    }
}
